package com.dong.c06_zero_copy;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

/**
 * <h1></h1>
 *
 * @author : dzj
 * @create: 2020-03-18 21:00
 */
public class NioServer {
    public static void main(String[] args) throws IOException {
        InetSocketAddress inetSocketAddress = new InetSocketAddress(7001);
        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
        serverSocketChannel.socket().bind(inetSocketAddress);

        ByteBuffer buffer = ByteBuffer.allocate(4096);
        while(true) {
            SocketChannel socketChannel = serverSocketChannel.accept();
            int readCount = 0;
            while(readCount!=-1) {
                try {
                    readCount= socketChannel.read(buffer);

                }finally {

                }
                //倒带
                buffer.rewind();//position=0, mark -1作废
            }
        }
    }
}
